#!/usr/bin/env python
##================
##gui example
##================
import pygame,sys
import lwpgt

#main screen variable
SCREEN=pygame.display.set_mode((640,480))
#init pygame
pygame.init()
pygame.key.set_repeat(300,50)
pygame.display.set_caption("Gui example ListCtrl")

class guiexample02:
    """gui example 2"""
    def __init__(self):
        """init example"""
        #creating main container
        self.maincontainer=lwpgt.gui.Container()
        #creating widgets
        self.textbox=lwpgt.gui.TextBox(text="Click here to edit..",textsize=15,position=(100,70))
        self.listctrl=lwpgt.gui.ListCtrl(None, pos=(100, 100), size=(100, 150), unselectable=False)
        #setting widgets
        self.listctrl.Connect(lwpgt.EVT_LISTSELECT, self.onselect)
        self.listctrl.SetList(["siemka","a","b","C","option","option-2","menu entry","look at","some text"])
        #add to container
        self.maincontainer.Add(self.textbox)
        self.maincontainer.Add(self.listctrl)
        
    def update(self):
        """update example"""
        pass
    
    def onselect(self, widget):
        """on listctrl select callback"""
        print "selected", widget.GetSelected()
    
    ## redraw
    def redraw(self,screen):
        screen.fill((0,0,0))
        ##drawing here
        self.maincontainer.Redraw(screen)
        pygame.display.flip()
        
    def events(self):
        """events handler for example"""
        for e in pygame.event.get():
            self.maincontainer.PollEvent(e)
            if e.type==pygame.QUIT:
                sys.exit()
            if e.type==pygame.KEYDOWN:
                pass
        
    def mainloop(self):
        """maqinloop"""
        while 1:
            self.events()
            self.update()
            self.redraw(SCREEN)

if __name__=="__main__":
    guiexample02().mainloop()
